﻿using Guest_room.BLL;
using System;
using System.Data;
using System.Drawing;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http.Json;
using System.Text.Json.Serialization;
using System.Text;
using Newtonsoft.Json;

namespace Guest_room
{
    public partial class CHX_Product : Form
    {
        public CHX_Product()
        {
            InitializeComponent();
        }

        GuestRoomService guestRoomService = new GuestRoomService();
        private void CHX_Product_Load(object sender, EventArgs e)
        {
            var (dtCustomerDetails, dtStayInfo) = guestRoomService.GetCustomerInfo(Default.pro_id);

            if (dtStayInfo.Rows.Count == 0)
            {
                MessageBox.Show("没有相关查询结果");
            }
            else
            {
                foreach (DataRow row in dtStayInfo.Rows)
                {
                    label12.Text = row["客户编号"].ToString();//客户编号
                    label13.Text = dtCustomerDetails.Rows[0]["客户姓名"].ToString();//客户姓名
                    label14.Text = dtCustomerDetails.Rows[0]["客户性别"].ToString();//客户性别
                    label15.Text = dtCustomerDetails.Rows[0]["客户身份证"].ToString();//客户身份证
                    label16.Text = row["客房编号"].ToString();//客房编号
                    label17.Text = row["入住日期"].ToString();//入住日期
                    label18.Text = row["退房日期"].ToString();//退房日期
                    label19.Text = dtCustomerDetails.Rows[0]["入住经办员"].ToString();//入住经办员
                    label20.Text = dtCustomerDetails.Rows[0]["退房经办员"].ToString();//退房经办员
                    label21.Text = row["预计入住时长"].ToString();//预计入住时长
                    label22.Text = row["房间金额"].ToString();//房间金额
                    pictureBox1.Image = Image.FromFile(Application.StartupPath + "" + dtCustomerDetails.Rows[0]["客户身份证照片"].ToString() + "");//加载图片
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;//自适应图片尺寸大小
                    listBox1.Items.Add("  客户编号: " + row["客户编号"]);
                    listBox1.Items.Add("  客户姓名: " + dtCustomerDetails.Rows[0]["客户姓名"]);
                    listBox1.Items.Add("  客户性别: " + dtCustomerDetails.Rows[0]["客户性别"]);
                    listBox1.Items.Add("  客户身份证: " + dtCustomerDetails.Rows[0]["客户身份证"]);
                    listBox1.Items.Add("  客房编号: " + row["客房编号"]);
                    listBox1.Items.Add("  入住日期: " + row["入住日期"]);
                    listBox1.Items.Add("  退房日期: " + row["退房日期"]);
                    listBox1.Items.Add("  入住经办员: " + dtCustomerDetails.Rows[0]["入住经办员"]);
                    listBox1.Items.Add("  退房经办员: " + dtCustomerDetails.Rows[0]["退房经办员"]);
                    listBox1.Items.Add("  预计入住时长: " + row["预计入住时长"]);
                    listBox1.Items.Add("  房间金额: " + row["房间金额"]);
                }
            }
        }


        private void button1_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)//查询上一个
        {

        }

        private void button3_Click(object sender, EventArgs e)//查询下一个
        {

        }

        private async void MvcBt_Click(object sender, EventArgs e)
        {
            var customerInfo = new
            {
                CustomerId = label12.Text,
                CustomerName = label13.Text,
                CustomerGender = label14.Text,
                CustomerIdCard = label15.Text,
                RoomId = label16.Text,
                CheckInDate = label17.Text,
                CheckOutDate = label18.Text,
                CheckInOfficer = label19.Text,
                CheckOutOfficer = label20.Text,
                ExpectedStayDuration = label21.Text,
                RoomAmount = label22.Text,
                CustomerPhotoPath = pictureBox1.ImageLocation
            };

            string url = "http://localhost:60689/CustomerInfo/DisplayInfo";
            // 序列化客户信息为JSON
            string json = JsonConvert.SerializeObject(customerInfo);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            // 创建HttpClient实例
            using (HttpClient client = new HttpClient())
            {
                // 发送POST请求
                HttpResponseMessage response = await client.PostAsync(url, content);

                // 获取并打印服务器响应
                string responseContent = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseContent);
            }
        }
    }
}
